

/*******************************************************************************
 * 填写完本月底计划能结的时候计算预计回款完成情况和实际完成情况
 * @param obj
 * @return
 */
function fx_blMoney(obj) {
    if ($(obj).attr("chan") != "T") {
        return;
    }


    var amount = $(obj).val() == "" ? 0 : $(obj).val();
    var curDiv = $("div[realdsid][prefix][dsid]"); // 获取datagrid的div
    var currentRow = $(curDiv).datagrid("getEditRow"); // 获取正在编辑的行
    var i = $(curDiv).datagrid("getRowIndex", currentRow);

    //if(amount ==null || amount == "" || amount == 0 ) return;

    currentRow["PLAN_MONEY"] = amount; // 因为数量是可编辑的框，所以此处必须显示赋值，否则
    // 计算通用的明细统计的计算方法中使用的数量有可能是上一次的值

    if(currentRow["PLAN_MONEY"] !=null && currentRow["PLAN_MONEY"] !=0){
        // 预计回款完成情况 = 本月实际回款/本月底计划能结
        currentRow["PLAN_PERFORMANCE"] = (parseFloat(currentRow["RETURN_MONEY"] / currentRow["PLAN_MONEY"]))
            .toFixed(fixno); // 预计回款完成情况
    }

    //  实际完成情况  =  本月实际回款/本月实际应结
    if(currentRow["PAY_SHOULD"] != null && currentRow["PAY_SHOULD"] !="" && currentRow["PAY_SHOULD"] != 0){
        currentRow["REALITY_PERFORMANCE"] = (parseFloat(currentRow["RETURN_MONEY"] / currentRow["PAY_SHOULD"]))
            .toFixed(fixno); // 实际完成情况
    }
    //currentRow["PACKNUM"] = packnum;
    $($(curDiv).datagrid('getCellObj', {
        "index" : i,
        "colnName" : "PLAN_PERFORMANCE"
    })).text(Number(currentRow["PLAN_PERFORMANCE"])); // 预计回款完成情况
    $($(curDiv).datagrid('getCellObj', {
        "index" : i,
        "colnName" : "REALITY_PERFORMANCE"
    })).text(Number(currentRow["REALITY_PERFORMANCE"]));// 实际完成情况

}


function getcwKHHKJHAccount(){


    $('#khhkjh_addItemDatagrid').datagrid('loadData',{total:0,rows:[]});

    var KH_DATE = $('#khhkjh_addWinForm input[qucln=KH_DATE]').val();


    var JIAFANG = $("#khhkjh_addWinForm input[qucln=O_ID_LASTGR]").val();


    if(KH_DATE!=null && KH_DATE!="" && JIAFANG!=null  && JIAFANG!="") {
        $.messager.alert('提示','正在查询，请稍候...');
        $.ajax({
            type:'post',
            url:_m_url + 'fxa/getcontractnobykhhkjh?KH_DATE='+KH_DATE,
            data:{
                'VENDOR_ID': JIAFANG
            },
            success:function(data){

                for ( var j = 0; j < data.length; j++) {
                    //alert(data[j].CLIENTS_NAME);
                    //alert(data[j].HISTORY_DEPT);
                    //alert(data[j].RECEIVABL_THIS);
                    $('#khhkjh_addItemDatagrid').datagrid('appendRow', {
                        CLIENTS_ID:data[j].CLIENTS_ID,
                        CLIENTS_NAME:data[j].CLIENTS_NAME,
                        PROVINCE_ID:data[j].PROVINCE_ID,
                        CC_ID:data[j].CC_ID,
                        HISTORY_DEPT:data[j].HISTORY_DEPT,
                        RECEIVABL_THIS:data[j].RECEIVABL_THIS,
                        RECEIVABL_NEXT:data[j].RECEIVABL_NEXT,
                        PAY_SHOULD:data[j].PAY_SHOULD,
                        SUM_DEPT:data[j].SUM_DEPT,
                        PLAN_MONEY:data[j].PLAN_MONEY,
                        RETURN_MONEY:data[j].RETURN_MONEY,
                        PLAN_PERFORMANCE:data[j].PLAN_PERFORMANCE,
                        REALITY_PERFORMANCE:data[j].REALITY_PERFORMANCE,
                        LAST_RETURN:data[j].LAST_RETURN

                    });
                }

            }
        })
    }
}




/**
 * 纸厂对账单的删除明细的按钮
 */
function deleteKHHKJH(obj,dgUrl,queryParams){
    // 获取选中的行
    var oldRows = $('#khhkjh_addItemDatagrid').datagrid('getSelections');
    for(var i=0;i<oldRows.length;i++){
        var rowIndex= $('#khhkjh_addItemDatagrid').datagrid('getRowIndex',oldRows[i]);
        $('#khhkjh_addItemDatagrid').datagrid('deleteRow',rowIndex);
    }
}